package com.itheima;

import com.itheima.dao.AccountDao;
import com.itheima.pojo.Account;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2020-08-14 11:25
 * @description 测试使用mybatis是否正常!!!!
 */
public class App01 {
    public static void main(String[] args) {
        //创建 sqlSessionFactoryBuilder
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();

        //创建sqlSessionFactory 由于需要使用sqlSessionFactoryBuilder创建

        InputStream inputStream = App01.class.getClassLoader().getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = builder.build(inputStream);
        //需要sqlSession

        SqlSession sqlSession = sqlSessionFactory.openSession(false);


        //执行逻辑

        AccountDao accountDao = sqlSession.getMapper(AccountDao.class);

        Account account = new Account();
        account.setName("小户");
        account.setMoney(1000);
        accountDao.save(account);

        sqlSession.commit();


        //关闭资源

        sqlSession.close();








    }
}
